package com.disapand.strongarmy.model

import org.ktorm.database.*
import org.ktorm.entity.*
import org.ktorm.schema.*

/**
 *
 * @auth disapand
 * @date 2021/11/5 - 17:54 - 星期五
 *
 */
interface Menu : Entity<Menu>, BaseModel {
    companion object: Entity.Factory<Menu>()

    var name: String
    var path: String
    var icon: String
    var parentId: Int
    var weight: Int
}

open class Menus(alias: String?) : Table<Menu>("sa_menu", alias) {
    companion object: Menus(null)
    override fun aliased(alias: String) = Menus(alias)

    val id = int("id").primaryKey().bindTo { it.id }
    val name = varchar("name").bindTo { it.name }
    val path = varchar("path").bindTo { it.path }
    val icon = varchar("icon").bindTo { it.icon }
    val parentId = int("parent_id").bindTo { it.parentId }
    val weight = int("weight").bindTo { it.weight }
    val status = int("status").bindTo { it.status }
    val deleted = boolean("deleted").bindTo { it.deleted }
    val createdBy = int("created_by").bindTo { it.createdBy }
    val createdAt = datetime("created_at").bindTo { it.createdAt }
    val updatedBy = int("updated_by").bindTo { it.updatedBy }
    val updatedAt = datetime("updated_at").bindTo { it.updatedAt }
}

val Database.menus get() = this.sequenceOf(Menus)